package com.epam.ws.anatomist.test;

import java.util.Properties;

import com.epam.tag1.tacc.soa.phase2.scrum.master.messages.RequestType;
import com.epam.ws.anatomist.common.ApplicationStorage;
import com.epam.ws.anatomist.message.MessageBuilder;
import com.epam.ws.anatomist.message.PropertiesGenerator;
import com.epam.ws.anatomist.message.TemplateEntity;
import com.epam.ws.anatomist.message.TemplatePojoEntity;

public class MessageFactory
{

	private static ApplicationStorage applicationStorage = ApplicationStorage.newInstance("test.cfg.xml");

	public static RequestType buildRequest(String requestCfgName, Properties predefinedProperties)
	{
		TemplatePojoEntity templatePojoEntity = applicationStorage.getTemplatePojoEntity(requestCfgName);
		TemplateEntity templateEntity = templatePojoEntity.getTemplateEntity();
		Properties dataSource = templateEntity.getDataSource();
		if (dataSource != null)
		{
			dataSource.putAll(predefinedProperties);
		}
		else
		{
			templateEntity.setDataSource(predefinedProperties);
		}
		PropertiesGenerator.scanPropertiesAndGenerate(templateEntity.getDataSource());
		return MessageBuilder.buildPojoEntity(templatePojoEntity);
	}


}
